
package Launcher;

import Modelos.TblUsuarios;
import java.util.List;
import javax.swing.JOptionPane;


public class Acceso extends javax.swing.JFrame {
    public Acceso() {
        initComponents();
        this.setLocationRelativeTo(null);
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GoBoxEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("goBox").createEntityManager();
        jPanel1 = new javax.swing.JPanel();
        pnlRedondo1 = new org.edisoncor.gui.panel.PanelNice();
        panelImage1 = new org.edisoncor.gui.panel.PanelImage();
        txtMensaje1 = new Componentes.Texfields.txtMensaje();
        txtPassword1 = new Componentes.Texfields.txtPassword();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(Configuraciones.Configuraciones.NOMBRE_APP);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(121, 137, 167));

        pnlRedondo1.setBackground(new java.awt.Color(220, 230, 240));
        pnlRedondo1.setBorderColor(new java.awt.Color(121, 137, 167));

        panelImage1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/Imagenes/gobox_mini.png"))); // NOI18N
        panelImage1.setMinimumSize(new java.awt.Dimension(64, 64));
        panelImage1.setPreferredSize(new java.awt.Dimension(64, 64));

        org.jdesktop.layout.GroupLayout panelImage1Layout = new org.jdesktop.layout.GroupLayout(panelImage1);
        panelImage1.setLayout(panelImage1Layout);
        panelImage1Layout.setHorizontalGroup(
            panelImage1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 64, Short.MAX_VALUE)
        );
        panelImage1Layout.setVerticalGroup(
            panelImage1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 64, Short.MAX_VALUE)
        );

        txtMensaje1.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        txtMensaje1.setFrase("Usuario");
        txtMensaje1.setOpaque(true);

        txtPassword1.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        txtPassword1.setFrase("Contraseña");
        txtPassword1.setOpaque(true);

        jButton1.setText("Entrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout pnlRedondo1Layout = new org.jdesktop.layout.GroupLayout(pnlRedondo1);
        pnlRedondo1.setLayout(pnlRedondo1Layout);
        pnlRedondo1Layout.setHorizontalGroup(
            pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo1Layout.createSequentialGroup()
                .addContainerGap()
                .add(pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(txtPassword1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 251, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton1)
                    .add(pnlRedondo1Layout.createSequentialGroup()
                        .add(panelImage1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtMensaje1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 251, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(48, Short.MAX_VALUE))
        );
        pnlRedondo1Layout.setVerticalGroup(
            pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(pnlRedondo1Layout.createSequentialGroup()
                .add(22, 22, 22)
                .add(pnlRedondo1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(panelImage1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(txtMensaje1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(txtPassword1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 391, Short.MAX_VALUE)
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(8, 8, 8)
                    .add(pnlRedondo1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(8, 8, 8)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 234, Short.MAX_VALUE)
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(8, 8, 8)
                    .add(pnlRedondo1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(8, 8, 8)))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      List<TblUsuarios>  Usuarios= GoBoxEntityManager.createNamedQuery("TblUsuarios.findByUsuario")
                .setParameter("usuario", txtMensaje1.getText()).getResultList();
      String password= String.valueOf(txtPassword1.getPassword());
      boolean ban=true;
        for (TblUsuarios usuario : Usuarios) {
            if(usuario.getContrasena().equals(password)){
                new GoBox(usuario.getTblPerfilesUsuariosCollection()).setVisible(true);
                ban=false;
                this.setVisible(false);
            } 
        }
        if(ban)
        JOptionPane.showMessageDialog(null,"Usuario y/o contraseña Incorrectos.","Iniciar Sesión",1);   
    }//GEN-LAST:event_jButton1ActionPerformed

    public static void main(String args[]) {
       
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Acceso().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager GoBoxEntityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private org.edisoncor.gui.panel.PanelImage panelImage1;
    private org.edisoncor.gui.panel.PanelNice pnlRedondo1;
    private Componentes.Texfields.txtMensaje txtMensaje1;
    private Componentes.Texfields.txtPassword txtPassword1;
    // End of variables declaration//GEN-END:variables
}
